﻿@model Mango.Web.Models.CartDto

@if (Model.CartHeader != null && Model.CartDetails.Count() > 0)
{
    <form method="post">
        <br />
        <input asp-for = "CartHeader.UserId" hidden />
        <input asp-for="CartHeader.CartHeaderId" hidden />
        <div class="">
            <div class="card border mt-4 container">
                <div class="card-header bg-dark text-light ml-0 row ">
                    <div class="col-6">
                        <i class="fa fa-shopping-cart"></i> &nbsp;
                        Корзина покупок
                    </div>
                    <div class="col-6 text-end">
                        <a asp-action="Index" asp-controller="Home" class="btn btn-outline-warning btn-sm">Продолжить покупки</a>
                    </div>
                </div>
                <div class="card-body">
                    <div class=" d-none d-lg-block">
                        <div class="row text-info">
                            <div class="col-lg-2">
                            </div>
                            <div class="col-lg-5">
                                Продукт
                            </div>
                            <div class="col-lg-2">
                                Цена
                            </div>
                            <div class="col-lg-2">
                                Количество
                            </div>
                            <div class="col-lg-1">
                            </div>
                        </div>
                    </div>

                    <hr />


                    @foreach(var cartObj in Model.CartDetails)
                    {
                    <div class="row h-100">
                        <div class="col-4 col-md-2 text-center py-2">
                            <img src="@cartObj.Product.ImageUrl" class="rounded" width="100%" />
                        </div>
                        <div class="col-8 col-md-5">
                            <h5>@cartObj.Product.Name</h5>
                                <div style="font-size:11px;">@Html.Raw(cartObj.Product.Description)</div>
                        </div>
                        <div class="col-3 col-md-2 pt-md-4" style="font-size:11px;">
                            <span style="font-size:17px;">@string.Format("{0:c}", cartObj.Product.Price)</span>
                        </div>
                        <div class="col-3 col-md-2 pt-md-4" style="font-size:11px;">
                            <span style="font-size:17px;">@cartObj.Count</span>
                        </div>
                        <div class="col-2 col-lg-1 p-0 pt-lg-4 text-center">
                            <a asp-action="Remove" asp-route-cartDetailsId="@cartObj.CartDetailsId" class="btn btn-outline-danger">
                                <i class="fas fa-trash"></i>
                            </a>
                        </div>
                    </div>
                    <hr />
                    }
                    <div class="row">
                        <div class="col-6">
                            @if(string.IsNullOrEmpty(Model.CartHeader.CouponCode))
                            {
                                <span>Купон:</span>
                                <input asp-for="CartHeader.CouponCode"/>
                                <button type="submit" asp-action="ApplyCoupon" class="btn-success"> Применить </button>
                            }
                            else
                            {
                                <span>Купон:</span>
                                <input asp-for="CartHeader.CouponCode" disabled/>
                                <button type="submit" asp-action="RemoveCoupon" class="btn-danger"> Удалить </button>
                            }

                        </div>
                        <div class="col-6 text-end">
                            <span class="text-danger" style="font-size:21px;">  Сумма : @string.Format("{0:c}", Model.CartHeader.OrderTotal) <br /></span>
                            @if(Model.CartHeader.DiscountTotal>0)
                            {
                                <span class="text-success"> Скидка: @string.Format("{0:c}", Model.CartHeader.DiscountTotal)</span>
                            }
                        </div>
                    </div>
                </div>
                <div class="card-footer row">
                    <div class="col-6 col-md-3 offset-md-6">
                    </div>
                    <div class="col-6 col-md-3">
                        <a asp-action="Checkout" class="btn btn-success form-control ">
                            <span>Заказать</span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </form>
}
else
{
    <div>
        <p>Пожалуйста добавьте товары в корзину.</p>
    </div>
}